

#delimit;
cap cd "C:\Users\ejm5\Dropbox\PAPI conjoint\Replication";
cap cd "/Users/paulschuler/Dropbox/projects/PAPI conjoint/Replication";
import excel "RawData\candidates2016.xlsx", sheet("Sheet1") firstrow case(lower) clear;
*import excel "RawData/candidates2016.xlsx", sheet("Sheet1") firstrow case(lower) clear;
save candidate.dta, replace;


#delimit;
use candidate.dta, clear;
generate result100=result*100;

label variable party  "Member of Party";
label values party party;
label define party 0 "Non-Party" 1 "Party";

#delimit;
cibar result100, over1(party) level(95) barcolor(ltblue navy) barlabel(on) blsize(medsmall)  blposition(NE)
graphopts(scheme(s1color) ytitle("Share of Delegates Elected (%)", size(medium) margin(medium)) legend(rows(2) ring(0) position(11) size(small)) 
title("Victory Share", size(large) margin(medium)) ylab(0(5)60));
graph save "Figures/NA_party1.gph", replace;


#delimit;
cibar percentage, over1(party)  level(95) barcolor(ltblue navy) barlabel(on) blsize(medsmall)  blposition(NE)
graphopts(scheme(s1color) ytitle("Average Vote Share (%)", size(medium) margin(medium)) legend(off) 
title("Vote Share", size(large) margin(medium)) ylab(0(5)60));
graph save "Figures/NA_party2.gph", replace;

graph combine "Figures/NA_party1.gph" "Figures/NA_party2.gph", ycommon imargin(tiny) note("95% Confidence Intervals; Victory Share is percent winning; Vote Share is percentage of vote", size(vsmall)) scheme(s1color);
graph save "Figures/Figure1.gph", replace;
graph export "Figures/Figure1.pdf"; replace


/*Ebalance*/

#delimit;
ebalance party birthyear south incumbent election_age male minority degree teach doctor business vna military centralnominated politburo self;


reg result100 party;
outreg2 using "Tables\Table2", tdec(3) bdec(3) e(rmse)  replace;
reg percentage party;
outreg2 using "Tables\Table2", tdec(3) bdec(3) e(rmse);
reg result100 party [aweight=_webal];
outreg2 using "Tables\Table2", tdec(3) bdec(3) e(rmse);
reg percentage party [aweight=_webal];
outreg2 using "Tables\Table2", tdec(3) bdec(3) e(rmse);
areg result100 party [aweight=_webal], absorb(province);
outreg2 using "Tables\Table2", tdec(3) bdec(3) e(rmse);
areg percentage party [aweight=_webal], absorb(province);
outreg2 using "Tables\Table2", tdec(3) bdec(3) e(rmse) excel;





